package cn.zhiyuan.ours.controller;

import java.util.List;

import com.jfinal.core.Controller;
import com.jfinal.kit.Base64Kit;

import cn.zhiyuan.ours.model.User;

public class UserController extends Controller {
	private User user = new User();

	public void index() {
		List<User> userlist = null;
		user = this.getSessionAttr("usersession");
		userlist = this.user.find("select * from `user`");
		this.setAttr("loginuserrole", user.getInt("role"));
		this.setAttr("userlist", userlist);
		this.render("user.html");
	}

	public void add() {
		this.render("add.html");
	}

	public void save() {
		user.set("user", this.getPara("user")).set("name", this.getPara("name")).set("email", this.getPara("email"))
				.set("sex", this.getPara("sex")).set("password",Base64Kit.encode("123456"));
		user.save();
		this.redirect("/#user");
	}
}
